import requests
import execjs
import json

with open('BirdsCode.js',mode='r',encoding='utf-8') as file:
    jsFile = file.read()
ctx = execjs.compile(jsFile)
result = ctx.call('getData',1)
timestamp = result['timestamp']
requestId = result['requestId']
sign = result['sign']
data = result['data']

headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
    'Connection': 'keep-alive',
    'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
    'Origin': 'https://www.birdreport.cn',
    'Referer': 'https://www.birdreport.cn/',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-site',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0',
    'requestId': f'{requestId}',
    'sec-ch-ua': '"Chromium";v="122", "Not(A:Brand";v="24", "Microsoft Edge";v="122"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
    'sign': f'{sign}',
    'timestamp': f'{timestamp}',
}
with open('Decrypt.js',mode='r',encoding='utf-8') as file:
    DecryptCode = file.read()

decrypt = execjs.compile(DecryptCode)


data = f'{data}'
response = requests.post(
    'https://api.birdreport.cn/front/activity/search',
    headers=headers,
    data=data)
resp = response.json()
BirdData = resp['data']
# print(BirdData)
dec_Data = decrypt.call('GetData',BirdData)
print(dec_Data)